<template>
  <view>



    <view class="gui-list gui-margin-top gui-padding-x gui-bg-white">
      <view class="gui-list-items">

        <view class="gui-list-body gui-border-b" @tap="editAvater">
          <view class="gui-list-title">
            <text class="gui-list-title-text">头像</text>
            <view>
              <image class="gui-list-image ucenter-face-image" :src="userInfo.image?baseUrl+userInfo.image:userAvater"
                mode="aspectFill">
              </image>
            </view>
          </view>
        </view>

        <text class="gui-list-arrow-right gui-icons gui-color-gray">&#xe601;</text>

      </view>
      <view class="gui-list-items">

        <view class="gui-list-body gui-border-b">
          <view class="gui-list-title">
            <text class="gui-list-title-text">用户名</text>
            <!-- <text class="gui-color-gray"></text> -->
            <input class="gui-list-arrow-right gui-icons gui-color-gray gui-flex1" @confirm="editNickname"
              v-model="userInfo.nickName" />
          </view>
        </view>

        <text class="gui-list-arrow-right gui-icons gui-color-gray"> &#xe601;</text>
      </view>

      <view class="gui-list-items" @click="gotoRealAuth">

        <view class="gui-list-body gui-border-b">
          <view class="gui-list-title">
            <text class="gui-list-title-text">实名认证</text>

          </view>
        </view>

        <text class="gui-list-arrow-right gui-icons gui-color-gray"> &#xe601;</text>
      </view>
    </view>

    <view class="gui-padding-x gui-bg-white gui-margin-top">
      <view class="gui-list-items" @click="getPhone">

        <view class="gui-list-body gui-border-b">
          <view class="gui-list-title">
            <text class="gui-list-title-text">帮助中心</text>
          </view>
        </view>
        <text class="gui-list-arrow-right gui-icons gui-color-gray">&#xe601;</text>
      </view>
      <view class="gui-list-items" @click="goFeedback">

        <view class="gui-list-body gui-border-b">
          <view class="gui-list-title">
            <text class="gui-list-title-text">意见反馈</text>
          </view>
        </view>
        <text class="gui-list-arrow-right gui-icons gui-color-gray">&#xe601;</text>
      </view>
    </view>

  </view>
</template>
<script>
  import graceJS from '@/Grace6/js/grace.js';
  export default {

    data() {
      return {
        contentHeight: 300,
        userInfo: {},
        userAvater: '/static/images/touxiang.png',
        baseUrl: uni.gRequest.file,

      }
    },
    mounted() {
      var user = uni.gRequest.checkLogin();
      // console.log("是否登录", user)
      if (user) {
        this.userInfo = user

        if (user.user_avater) {
          this.userAvater = uni.gRequest.server.replace('/app/', '') + user.user_avater;
        }

      }
      var systemInfo = graceJS.system();
      this.contentHeight = systemInfo.windowHeight * 0.65;

    },
    methods: {
      gotoRealAuth() {
        uni.navigateTo({
          url: "/pages/realauth/realauth"
        })
      },
      // 获取客服电话
      getPhone() {
        uni.gRequest.get('dict/get/information', {
          key: 'service.phone'
        }).then(result => {
          uni.showModal({
            title: '联系客服',
            content: result.msg,
            showCancel: true,
            cancelText: '取消',
            confirmText: '呼叫',
            success: res => {
              if (res.confirm) {
                uni.makePhoneCall({
                  phoneNumber: res.content
                })
              }

            },
            fail: () => {},
            complete: () => {}
          });
        });
      },
      // 意见反馈
      goFeedback() {
        uni.navigateTo({
          url: '/pages/user/feedback'
        })
      },
      editAvater() {

        var self = this;

        uni.chooseImage({
          count: 1,
          success: (res) => {
            //self[x] = res.tempFilePaths[0];

            uni.showLoading({
              title: "请稍等"
            })

            uni.uploadFile({
              url: uni.gRequest.server + 'file/upload',
              filePath: res.tempFilePaths[0],
              header: {
                "Authori-zation": self.userInfo.token
              },
              name: 'file',
              success: (uploadResult) => {

                var fileName = JSON.parse(uploadResult.data).fileName;
                self.userAvater = JSON.parse(uploadResult.data).url;
                uni.gRequest.get("user/edit/image", {
                  id: self.userInfo.userId,
                  img: fileName
                }).then(x => {
                  self.userInfo.image = fileName;
                  uni.setStorageSync("userInfo", self.userInfo);
                  uni.hideLoading();





                });

              }

            })


          }
        })
      },
      editNickname() {
        // console.log('1111111111', this.userInfo);
        var self = this;
        uni.gRequest.get("user/edit/nickname", {
          id: self.userInfo.userId,
          nickName: self.userInfo.nickName
        }).then(x => {
          uni.showToast({
            title: "修改成功"
          })
          uni.setStorageSync("userInfo", self.userInfo);
        });

      }

    }
  }
</script>
<style>

</style>
